--region *.lua
--Date
--此文件由[BabeLua]插件自动生成

local LoginData = class("LoginData");

function LoginData:ctor()
    self.level = 0;
    self.coin = 0;
    self.level = 0;
    self.gem = 0;
    self.clientKeepCount = 0;
    self.clientKeepMaxCount = 500;
    self.serverKeepTime = 0;
    self.clientKeepTime = 0;
    self.serverTime = 0;
    self.sessionTimeout = 0;
end

function LoginData:setCoin(coin)
    self.coin = coin;
end

function LoginData:getCoin()
    return self.coin;
end

function LoginData:setLevel(lv)
    self.level = lv;
end

function LoginData:getLevel()
    return self.level;
end

function LoginData:setGem(gem)
    self.gem = gem;
end

function LoginData:getGem()
    return self.gem;
end

function LoginData:parseBaseInfo(data)
    self:setCoin(data.coin);
    self:setLevel(data.lv);
    self:setGem(data.gem);
    mgrs.event:dispatchEvent({name = enums.Event.ShowRoleBaseInfo});
end

function LoginData:addSpareTime(dt)
    self.clientKeepTime = self.clientKeepTime + dt;
    if self.clientKeepTime >= self.serverKeepTime - 5 then
        self.clientKeepCount = self.clientKeepCount + 1;
        if self.clientKeepCount < self.clientKeepMaxCount then
            self.clientKeepTime = 0;
            mgrs.log:printDebug("keep_live");
            mgrs.proto:send(Protocol.C2A_KEEP_LIVE);
        else
            --客户端主动断开
            mgrs.log:printDebug("clientKeepCount  closeSocket");
            mgrs.proto:closeSocket();
        end
    end
end

function LoginData:keepLive(data)
    self.serverKeepTime = data.keeplive;
    self.serverTime = data.servertime;
    self.sessionTimeout = data.sessiontimeout;
end

function LoginData:reset()
    mgrs.log:printDebug("LoginData:reset");
    self.clientKeepTime = 0;
end

function LoginData:loginParse(data)
    mgrs.log:printDump(data);
end

return LoginData;

--endregion
